package cn.wjh.business.controller;

import cn.wjh.business.domain.WorksMark;
import cn.wjh.business.service.IWorksMarkService;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 作品打分Controller
 *
 * @author jiraWu
 * @date 2023-10-21
 */
@RestController
@RequestMapping("/business/worksMark")
public class WorksMarkController extends BaseController {
	@Resource
	private IWorksMarkService worksMarkService;

	/**
	 * 查询作品打分列表
	 */
//	@PreAuthorize("@ss.hasPermi('business:worksMark:list')")
	@Anonymous
	@GetMapping("/list")
	public TableDataInfo list(WorksMark worksMark) {
		startPage();
		List<WorksMark> list = worksMarkService.selectWorksMarkList(worksMark);
		return getDataTable(list);
	}

	/**
	 * 导出作品打分列表
	 */
//	@PreAuthorize("@ss.hasPermi('business:worksMark:export')")
	@Log(title = "作品打分", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	public void export(HttpServletResponse response, WorksMark worksMark) {
		List<WorksMark> list = worksMarkService.selectWorksMarkList(worksMark);
		ExcelUtil<WorksMark> util = new ExcelUtil<WorksMark>(WorksMark.class);
		util.exportExcel(response, list, "作品打分数据");
	}

	/**
	 * 获取作品打分详细信息
	 */
//	@PreAuthorize("@ss.hasPermi('business:worksMark:query')")
	@GetMapping(value = "/{markId}")
	public AjaxResult getInfo(@PathVariable("markId") Long markId) {
		return success(worksMarkService.selectWorksMarkByMarkId(markId));
	}

	/**
	 * 新增作品打分
	 */
//	@PreAuthorize("@ss.hasPermi('business:worksMark:add')")
	@Log(title = "作品打分", businessType = BusinessType.INSERT)
	@PostMapping
	public AjaxResult add(@RequestBody WorksMark worksMark) {
		return toAjax(worksMarkService.insertWorksMark(worksMark));
	}

	/**
	 * 修改作品打分
	 */
//	@PreAuthorize("@ss.hasPermi('business:worksMark:edit')")
	@Log(title = "作品打分", businessType = BusinessType.UPDATE)
	@PutMapping
	public AjaxResult edit(@RequestBody WorksMark worksMark) {
		return toAjax(worksMarkService.updateWorksMark(worksMark));
	}

	/**
	 * 删除作品打分
	 */
//	@PreAuthorize("@ss.hasPermi('business:worksMark:remove')")
	@Log(title = "作品打分", businessType = BusinessType.DELETE)
	@DeleteMapping("/{markIds}")
	public AjaxResult remove(@PathVariable Long[] markIds) {
		return toAjax(worksMarkService.deleteWorksMarkByMarkIds(markIds));
	}

	/**
	 * 根据用户Id 作品Id 获取打分详细
	 *
	 * @param worksId 作品Id
	 * @return 打分详细
	 */
	@GetMapping("/init/{worksId}")
	public AjaxResult getInfoByWorksIdAndUserId(@PathVariable Long worksId) {
		return success(worksMarkService.getInfoByWorksIdAndUserId(worksId, getUserId()));
	}
}
